<?PHP
	!defined('DYHB_PATH') && exit;
	class UserController extends InitController{
		public function check_login(){
			$sUserName=G::getGpc('user_name','p');
			$sUserPassword=G::getGpc('user_password','p');
			sleep(1);
			$sUserPassword=md5($sUserPassword.ENCODE);
			$arrJudge=array('regname'=>$sUserName,'regpassword'=>$sUserPassword);
			$oUser=UserModel::F($arrJudge)->getOne();
			if(!empty($oUser->user_id)){
				Dyhb::cookie('user_login',$oUser->toArray());
				//$this->assign('__JumpUrl__',Dyhb::U('index/index'));
				//$this->S('登陆成功');
				//header('Location:'.Dyhb::U('index/index'));
				echo 1;
			}else{
				//$this->assign('__JumpUrl__',Dyhb::U('public/login'));
				//$this->E('用户名或密码错误');
				echo 0;
			}
		}
		public function logout(){
			if($GLOBALS['___login___']){
				Dyhb::cookie('user_login',array());
				$this->assign("seconds",1);
				$this->assign("__JumpUrl__",Dyhb::U('public/login'));
				$this->S('登出成功');
			}else{
				$this->assign("seconds",1);
				$this->E('你已经成功登出');
			}
		}
		public function changePassword(){
			if($GLOBALS['___login___']==false){
				$this->assign('top','top');
				$this->E('此操作需要登陆后才能进行');
			}
			$arrPassword=G::getGpc('password','p');
			if($GLOBALS['___login___']['regpassword'] != md5($arrPassword['current'].ENCODE)){
				$this->E('密码错误');
			}
			if($arrPassword['new']!=$arrPassword['renew']){
				$this->E('两次输入的密码不一样');
			}
			$arrJudge=array('regname'=>$GLOBALS['___login___']['regname']);
			$oUser=UserModel::F($arrJudge)->getOne();
			$oUser->regpassword=md5($arrPassword['new'].ENCODE);
			$oUser->save(0,'update');
			if($oUser->isError()){
				$this->E('密码修改失败');
			}else{
				 Dyhb::cookie('user_login',array());
				$this->assign('top','top');
				$this->assign("__JumpUrl__",Dyhb::U('public/login'));
				$this->S('密码修改成功');
			}
		}
	}
?>